{\rtf1\mac\ansicpg10000\cocoartf824\cocoasubrtf410
{\fonttbl\f0\fswiss\fcharset77 Helvetica-Bold;\f1\fswiss\fcharset77 Helvetica;\f2\fnil\fcharset77 Monaco;
}
{\colortbl;\red255\green255\blue255;\red0\green0\blue255;\red191\green0\blue0;\red0\green0\blue191;
\red0\green0\blue0;\red191\green0\blue0;\red0\green0\blue191;}
\deftab560
\pard\pardeftab560\ql\qnatural

\f0\b\fs36 \cf0 Dfsm			
\fs24 demand rate finite state machine
\f1\b0 \
\

\f0\b Dfsm(rules, n, randgen)
\f1\b0 \
\
\
Similar to {\field{\*\fldinst{HYPERLINK "SC://Pfsm"}}{\fldrslt \cf2 Pfsm}}, 
\f0\b Dfsm
\f1\b0  implements a markov chain. Each state has a number of next states out of which one is randomly chosen.\
\
\

\f0\b rules
\f1\b0  - array in the format: \
[\
		 [ entry states ],\
	 	item, [ next states ],\
	 	item, [ next states ],\
		 ...\
	 	end item\
 ]\
\
Each 
\f0\b item
\f1\b0  can be a number, or a ugen, typically demand rate. If no 
\f0\b end item
\f1\b0  is given, 
\f0\b 0.0
\f1\b0  is used as default.\
 \

\f0\b n
\f1\b0  - number of items from each state to embed. If 
\f0\b inf
\f1\b0 , they are embedded completely.\
\

\f0\b randgen 
\f1\b0 - demand rate random number generator that should ouput values between 0.0 and 1.0. If a deterministic ugen is used, the choice of next states of the finite state machine can be controlled (i.e. 0 will allways choose the first, 1 always the last, else in between).\
\
\
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\pardeftab560\ql\qnatural\pardirnatural

\f2\fs18 \cf0 \
\
\
s.boot;\
\
\cf3 // random jumps\cf0 \
(\
\{\
	\cf4 var\cf0  a, b, trig = \cf4 Impulse\cf0 .kr(\cf4 MouseX\cf0 .kr(4, 100, 1));\
	a = \cf4 Dfsm\cf0 ([[1], 1.5, [0, 1], 2.5, [0, 1]]);\
	b = \cf4 Demand\cf0 .kr(trig, 0, a).poll(trig);\
	\cf4 SinOsc\cf0 .ar(b * 200 + 300) * 0.1\
\}.play\
);\
\
\cf3 // 2.5 may come after 1.5, but not the other way round.\cf0 \
(\
\{\
	\cf4 var\cf0  a, b, trig = \cf4 Impulse\cf0 .kr(\cf4 MouseX\cf0 .kr(4, 100, 1));\
	a = \cf4 Dfsm\cf0 ([[0], 1.5, [0, 0, 1], 2.5, [1, 2], 0.5, [0]]);\
	b = \cf4 Demand\cf0 .kr(trig, 0, a).poll(trig);\
	\cf4 SinOsc\cf0 .ar(b * 200 + 300) * 0.1\
\}.play\
);\
\
\
\cf5 \
\cf6 // embed demand ugens, embed 2 of each, end with series of 4, 5, 3.\cf5 \
(\
\{\
	\cf7 var\cf5  a, n = 2, trig = \cf7 Impulse\cf5 .kr(\cf7 MouseX\cf5 .kr(4, 100, 1));\
	a = \cf7 Dfsm\cf5 ([\
		[0], \cf6 // entry states\cf5 \
		\cf7 Dseq\cf5 ([-2, -3], \cf7 inf\cf5 ), [1], \
		\cf7 Dseq\cf5 ([1, 2, 1.5], \cf7 inf\cf5 ), [0, 0, 0, 1, 2], \
		\cf7 Dseq\cf5 ([4, 5, 3], \cf7 inf\cf5 ) \cf6 // exit state\cf5 \
	], n);\
	b = \cf7 Demand\cf5 .kr(trig, 0, a).poll(trig);\
	\cf7 SinOsc\cf5 .ar(b * 200 + 700) * 0.1\
\}.play\
);\cf0 \
\
\
\cf3 // direct audification\cf0 \
(\cf5 \
\{\
	\cf7 var\cf5  a, b, pseudorandomness;\
	pseudorandomness = \cf7 Dswitch1\cf5 ((0..1000).scramble / 1000, \cf7 Dwhite\cf5 (0, 1, \cf7 inf\cf5 )\
		* \cf7 MouseY\cf5 .kr(1, 1000, 1));\
	a = \{ \
		\cf7 Dfsm\cf5 ([\
			[0, 1, 2], \
			\cf7 Dseq\cf5 ([0, 0, 1], \cf7 inf\cf5 ), [1], \
			\cf7 Dseq\cf5 ([-1, 0].clipExtend(10.rand + 2), \cf7 inf\cf5 ), [2],\
			\cf7 Dseq\cf5 ([1, 0, -1, 0]\cf0 .clipExtend(10.rand + 4)\cf5 , \cf7 inf\cf5 ), [1, 1, 3, 0],\
			\cf7 Dwhite\cf5 (0, 1, \cf7 inf\cf5 ), [0],\
			0\
		], \
		\cf7 MouseX\cf5 .kr(1, 1115, 1),\
		pseudorandomness\
	) \} ! 10;\
	b = \cf7 Splay\cf5 .ar(\cf7 Duty\cf5 .ar(\cf7 SampleDur\cf5 .ir, 0, a)) * 0.1;\
\}.play\
\cf0 );\
\
\
\
\
}